package com.teamtwoseven.todo;

import android.location.Location;

public class Item implements Comparable<Item>{
	
	private long itemID, deadline;
	private String itemName, description, category, frequency;
	private boolean isDone;
	private String location; //Later will be type Location?
	
	
	public Item(long itemID, String itemName, String description,
		String category, long deadline, String frequency, String location,
		boolean isDone){
		
		this.itemID = itemID;
		this.itemName = itemName;
		this.description = description;
		this.category = category;
		this.deadline = deadline;
		this.frequency = frequency;
		this.location = location;
		this.isDone = isDone;
	}
	
	public long getItemID(){
		return itemID;
	}
	
	public String getName(){
		return itemName;
	}
	
	public String getDescription(){
		return description;
	}

	public String getCategory(){
		return category;
	}
	
	public long getDeadline(){
		return deadline;
	}
	
	public String getFrequency(){
		return frequency;
	}
	
	public String getLocation(){
		return location;
	}
	
	public boolean isDone(){
		return isDone;
	}
	
	/**
	 * Sets isDone to its opposite.
	 * 
	 * @return the new, opposite value of isDone
	 */
	public boolean toggleDone() {
		return (isDone = !isDone);
	}
	
	/**
	 * Compares this Item's deadline to that Item's deadline. Assumes neither
	 * Item is null.
	 * 
	 * @param that
	 * 			an Item to compare to this Item
	 * @return -1, 0, or 1 if this.getDeadline() is respectively less than,
	 * 			equal to, or greater than that.getDeadline()
	 */
	public int compareTo(Item that) {
		int result = 0;
		if(this.getDeadline() < that.getDeadline()) {
			result = -1;
		}
		else if(this.getDeadline() > that.getDeadline()) {
			result = 1;
		}
		return result;
	}
	
	/**
	 * Checks if this item is identical to that item. Two items are identical
	 * if all their fields (except itemID) are the same.
	 * 
	 * @param that
	 * 			an Item
	 * @return true if the items are identical, false otherwise
	 */
	public boolean isIdenticalTo(Item that) {
		boolean retVal = false;
		
		if (that != null) {
			retVal = this.getName().equals(that.getName()) &&
				this.getDescription().equals(that.getDescription()) &&
				this.getCategory().equals(that.getCategory()) &&
				this.compareTo(that) == 0 && 
				this.getFrequency().equals(that.getFrequency()) &&
				this.getLocation().equals(that.getLocation()) &&
				this.isDone() == that.isDone();
		}
		return retVal;
	}
}
